<?php
namespace app\index\controller;
use OSS\Core\OssException;
use OSS\OssClient;
use think\Controller;
use think\Db;
use think\Request;
use think\captcha\Captcha;
use think\facade\Session;
use think\facade\Config;


class Tuqing extends Base
{
    public function index()
    {

        //
        $a=Db::query("select * from lily_listkey where wname='Pitch Diametral'");
        //echo "<pre/>";print_r($a);exit;
        foreach ($a as $k=>$v){
           echo  "insert into lily_listkey (`class_id`,`wname`,`seq`) values (".$v['class_id'].",'Module',".$v['seq'].");";echo "<br/>";
        }
        //ROTEK ROTHEERDE
        /*
        $a=Db::query("select * from lily_products where bid=19");

        foreach ($a as $k=>$v){
            $b=Db::query("select * from lily_cross where FIND_IN_SET(".$v['id'].", pid)>0 ");
            //echo count($b);exit;
            //echo "<pre/>";print_r($b);exit;
            if($b&&count($b)==1){
                Db::query("update lily_cross set cb_id=146 where FIND_IN_SET(".$v['id'].", pid)>0");
            }elseif ($b&&count($b)>1){
                echo $v['id'].$v['url_product'].'<br/>';
            }
        }*/
        exit;

//echo strip_tags(htmlspecialchars_decode('<p class="PrsnttnCpy">Connect and separate threaded <span class="Wrd">rods,</span> <span class="Wrd">studs,</span> and other <span class="Wrd">components.</span> These hollow rods have internal threads on both <span class="Wrd">ends,</span> so you can make connections and still pass wiring and other objects through the center of the <span class="Wrd">rod.</span></p>'));exit;
        //seo
        $a=Db::query("select id from ((select id from lily_classify where fid in (select id from lily_classify where fid=795) or id in(select id from lily_classify where fid=795) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=795))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=795))) )
 UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1375) or id in(select id from lily_classify where fid=1375) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1375))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1375))) )
  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1656) or id in(select id from lily_classify where fid=1656) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1656))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1656))) )
	  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1744) or id in(select id from lily_classify where fid=1744) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1744))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1744))) )
			  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1823) or id in(select id from lily_classify where fid=1823) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1823))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1823))) )
							  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1842) or id in(select id from lily_classify where fid=1842) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1842))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1842))) )
 UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1843) or id in(select id from lily_classify where fid=1843) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1843))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1843))) )
  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1844) or id in(select id from lily_classify where fid=1844) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1844))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1844))) )
	  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1845) or id in(select id from lily_classify where fid=1845) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1845))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1845))) )
			  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1847) or id in(select id from lily_classify where fid=1847) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1847))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1847))) )
							  UNION (select id from lily_classify where fid in (select id from lily_classify where fid=1848) or id in(select id from lily_classify where fid=1848) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848))) ) union (select 1846 as id) UNION (select id from lily_classify where fid=1374)) as a ");
        //echo "<pre/>";print_r($a);exit;
        foreach ($a as $k=>$v){
            $b=Db::query("select * from lily_classify_seo where class_id='".$v['id']."'");


            if($b){
                echo " UNION select CONCAT('update lily_classify_seo set title=\"',`cname`,' | Lily Bearing\"',',keywords=\"',`cname`,'\",description=\"Select from LILY Bearing\'s diverse range of Inch Size ',`cname`,'. Expertly engineered for superior performance, find your perfect fit at a great price. \",filter_title=\"[SEOstr] ',`cname`,' | Lily Bearing\"',',filter_keywords=\"[SEOstr] ',`cname`,'\",filter_description=\"Select from LILY Bearing\'s diverse range of Inch Size ',`cname`,'. Expertly engineered for superior performance, find your perfect fit at a great price. \" where class_id=',id,';') from lily_classify where id=".$v['id']." </br>";
            }else{
                echo " UNION select CONCAT('insert lily_classify_seo (class_id,title,keywords,description)VALUES(',id,',\"',`cname`,' | Lily Bearing\",\"',`cname`,'\",\"Select from LILY Bearing\'s diverse range of Inch Size ',`cname`,'. Expertly engineered for superior performance, find your perfect fit at a great price. \");') from lily_classify where id=".$v['id']." </br>";
            }

        }

        //图片
/*
        $a=Db::query("select * from lily_listkey where class_id in(select id from lily_classify where fid in (select id from lily_classify where fid=1848) or id in(select id from lily_classify where fid=1848) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848)))) and is_images=1");

        foreach ($a as $k=>$v){
            $b=Db::query("select * from lily_listkey where class_id=1848 and is_images=1 and wname='".$v['wname']."'");

            $c=Db::query("select * from lily_listkey_images where list_key_id='".$b[0]['id']."'");

            foreach ($c as $kk=>$vv){
                if(!Db::query("select * from lily_listkey_images where list_key_id='".$v['id']."' and `value`='".$vv['value']."'")){
                    echo "insert into lily_listkey_images (`list_key_id`,`value`,`images`,`seq`) values (".$v['id'].",'".$vv['value']."','".$vv['images']."','".$vv['seq']."');</br>";
                }else{
                    continue;
                }

            }
        }
*/
        //reorder
/*
        $a=Db::query("select * from lily_listkey where class_id in(select id from lily_classify where fid in (select id from lily_classify where fid=1848) or id in(select id from lily_classify where fid=1848) or fid in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848))) or id  in (select id from lily_classify where id in (select id from lily_classify where fid in (select id from lily_classify where fid=1848)))) and is_reorder=1");
//echo "<pre/>";print_r($a);exit;
        foreach ($a as $k=>$v){
            $b=Db::query("select * from lily_listkey where class_id=1848 and is_reorder=1 and wname='".$v['wname']."'");

            $c=Db::query("select * from lily_listkey_reorder where list_key_id='".$b[0]['id']."'");

            foreach ($c as $kk=>$vv){
                if(!Db::query("select * from lily_listkey_reorder where list_key_id='".$v['id']."' and `value`='".$vv['value']."'")){
                    echo "insert into lily_listkey_reorder (`list_key_id`,`value`,`seq`) values (".$v['id'].",'".$vv['value']."','".$vv['seq']."');</br>";
                }else{
                    continue;
                }

            }
        }

*/
        echo 'suc';


    }

    public function sdsf(){
        set_time_limit(0);
/*
 * 1674  1675
 */
        $class_id=2068;
        $aid=2068;
        //$data=Db::connect(config::get('new.db_config1'))->table('lily_products')->field('part_number,id')->where([['class_id','=',$class_id]])->select();
        $data=Db::connect(config::get('new.db_config1'))->table('lily_products')->field('part_number,id')->where([['class_id','=',$class_id]])->select();

        //$b=Db::table('lily_class_detail_order')->field('fileds')->where('class_id','=',$aid)->find();
        /*不需要字段写在这里*/
        $arr=array('Product_Number','URL_Product','Part_Number','id','Price','class_id','technology_url','ids','class_name');//System_of_Measurement  Equivalent_to_Manufacturer

        foreach ($data as $key => $value) {
/*
            if(empty($b)){
                $a=Db::table('jingujian_screw')->where([['class_id','=',$aid],['Product_Number','=',$value['part_number']]])->find();
            }else{
                $a=Db::table('jingujian_screw')->field($b['fileds'])->where([['class_id','=',$aid],['Product_Number','=',$value['part_number']]])->find();}
*/
            $a=Db::table('h7_detail_metric_aaa')->where([['class_id','=',$aid],['Product_Number','=',$value['part_number']]])->find();
           // echo "<pre/>";print_r($a);exit;
            //'System of Measurement'
            $keyvalues=array(
                'System of Measurement'=>['seq'=>0,'name'=>'System of Measurement'],
                'Roller Bearing Type'=>['seq'=>1,'name'=>'Roller Bearing Type'],
                'For Load Direction'=>['seq'=>2,'name'=>'For Load Direction'],
                'Bore Diameter'=>['seq'=>3,'name'=>'Bore Diameter'],
                'Bore Diameter Tolerance'=>['seq'=>4,'name'=>'Bore Diameter Tolerance'],
                'Outside Diameter'=>['seq'=>5,'name'=>'Outside Diameter'],
                'Outside Diameter Tolerance'=>['seq'=>6,'name'=>'Outside Diameter Tolerance'],
                'Height'=>['seq'=>7,'name'=>'Height'],
                'Height Tolerance'=>['seq'=>8,'name'=>'Height Tolerance'],
                'Shoulder Diameter Inner Ring - Large Shoulder'=>['seq'=>9,'name'=>'Shoulder Diameter Inner Ring - Large Shoulder'],
                'Outer Ring (Housing Washer) Width'=>['seq'=>10,'name'=>'Outer Ring (Housing Washer) Width'],
                'Distance'=>['seq'=>11,'name'=>'Distance'],
                'Inner Ring (Shaft/Locating Washer) Hole Pitch Circle Diameter'=>['seq'=>12,'name'=>'Inner Ring (Shaft/Locating Washer) Hole Pitch Circle Diameter'],
                'Outer Ring (Housing Washer) Hole Pitch Circle Diameter'=>['seq'=>13,'name'=>'Outer Ring (Housing Washer) Hole Pitch Circle Diameter'],
                'Inner Ring (Shaft/Locating Washer) Through Hole'=>['seq'=>14,'name'=>'Inner Ring (Shaft/Locating Washer) Through Hole'],
                'Inner Ring (Shaft Washer) Sinkhole'=>['seq'=>15,'name'=>'Inner Ring (Shaft Washer) Sinkhole'],
                'Outer Ring (Housing Washer) Through Hole'=>['seq'=>16,'name'=>'Outer Ring (Housing Washer) Through Hole'],
                'Inner Ring (Shaft Washer) Sinkhole Depth'=>['seq'=>17,'name'=>'Inner Ring (Shaft Washer) Sinkhole Depth'],
                'Outer Ring (Housing Washer) Chamfer Dimension r1 (min.)'=>['seq'=>18,'name'=>'Outer Ring (Housing Washer) Chamfer Dimension r1 (min.)'],
                'Chamfer Dimension r2 (min.)'=>['seq'=>19,'name'=>'Chamfer Dimension r2 (min.)'],
                'Basic Dynamic Load Rating - Radial Direction'=>['seq'=>20,'name'=>'Basic Dynamic Load Rating - Radial Direction'],
                'Basic Static Load Rating - Radial Direction'=>['seq'=>21,'name'=>'Basic Static Load Rating - Radial Direction'],
                'Basic Dynamic Load Rating - Axial Direction'=>['seq'=>22,'name'=>'Basic Dynamic Load Rating - Axial Direction'],
                'Basic_Static_Load_Rating_-_Axial_Direction'=>['seq'=>23,'name'=>'Basic_Static_Load_Rating_-_Axial_Direction'],
                'Attainable Speed For Grease Lubrication'=>['seq'=>24,'name'=>'Attainable Speed For Grease Lubrication'],
                'Attainable Speed For Oil-Air Lubrication'=>['seq'=>25,'name'=>'Attainable Speed For Oil-Air Lubrication'],
                'Axial Preload'=>['seq'=>26,'name'=>'Axial Preload'],
                'Axial Unloading Force'=>['seq'=>27,'name'=>'Axial Unloading Force'],
                'Frictional Moment'=>['seq'=>28,'name'=>'Frictional Moment'],
                'Axial Stiffness For Preload A'=>['seq'=>29,'name'=>'Axial Stiffness For Preload A'],
                'Axial Stiffness For Preload B'=>['seq'=>30,'name'=>'Axial Stiffness For Preload B'],
                'Moment Stiffness'=>['seq'=>31,'name'=>'Moment Stiffness'],
                'Ring Material'=>['seq'=>32,'name'=>'Ring Material'],
                'Roller Material'=>['seq'=>33,'name'=>'Roller Material'],
                'Cage Material'=>['seq'=>34,'name'=>'Cage Material'],
                'Lubrication'=>['seq'=>35,'name'=>'Lubrication'],
                'Temperature Range'=>['seq'=>36,'name'=>'Temperature Range'],
                'RoHS'=>['seq'=>37,'name'=>'RoHS'],
                'REACH'=>['seq'=>38,'name'=>'REACH'],
                'Weight'=>['seq'=>39,'name'=>'Weight'],



            );

            foreach ($keyvalues as $kk => $vv) {
                foreach ($a as $k => $v) {

                    if(substr($k, -1)!='_'){
                        if(!in_array($k,$arr)){
                            if(!empty($v)&&$v!=''){
                                if($k=='ISO_radial'){
                                    $k='ISO radial <sup style="color:#36648a">1</sup>';
                                }
                                if($vv['name']==htmlentities(str_replace('_',' ',trim($k)))||(isset($vv['special'])&&$vv['special']&&$kk==htmlentities(str_replace('_',' ',trim($k))))){
                                    //echo isset($vv['seq'])&&$vv['seq']?$vv['seq']:'0';exit;
                                    echo "insert into lily_products_detail (`class_id`,`pid`,`key`,`value`,`seq`) values (".$class_id.",".$value['id'].",'".(isset($kk)&&$kk?$kk:htmlentities(str_replace('_',' ',trim($k))))."','".trim($v)."',".(isset($vv['seq'])&&$vv['seq']?$vv['seq']:'0').");</br>";

                                    //echo "update lily_products_detail set `value`='".trim($v)."',`seq`= '".(isset($vv['seq'])&&$vv['seq']?$vv['seq']:'0')."'where `key`='".(isset($kk)&&$kk?$kk:htmlentities(str_replace('_',' ',trim($k))))."' and `class_id`='".$class_id."'  and `pid`='".$value['id']."';</br>";
                                }

                            }
                        }
                    }
                }
            }
        }
    }

    /*获取型号*/
    public function xinghao(){
        $class_id=75;
        $aid=413;
        $data=Db::table('ball_bearings')->where('class_id','=',$aid)->select();

        //dump($data);exit;
        $arr=array('Product_Number','URL_Product','Price','System_of_Measurement','Equivalent_to_Manufacturer');
        foreach ($data as $key => $value) {
            $middle=Db::table('product_middle_table')->where('URL_Product','=',$value['URL_Product'])->find();

            echo "insert into lily_products (`class_id`,`part_number`,`url_product`,`Equivalent_to_Manufacturer`,`price`,`system`,`img`,`dimg`,`pdf`,`stp`,`other`) values (".$class_id.",'".$value['Product_Number']."','".$value['URL_Product']."','".htmlentities('<a href=\"/ball-bearing/angular-contact-ball-bearings/\" class=\"type4\">'.$value['Equivalent_to_Manufacturer'].'</a>')."','".$value['Price']."','".$value['System_of_Measurement']."','".$middle['img']."','".$middle['dimg']."','".$middle['pdf']."','".$middle['stp']."','".$middle['other']."');</br>";
        }
    }



    public function xinghaono(){
        $class_id=2068;//新class id
        $aid=2068;
        //$data=Db::table('oring')->where('class_id','=',$aid)->select();
        $data=Db::table('h7_detail_metric_aaa')->where([['class_id','=',$aid]])->select();
        //dump($data);exit;
        $arr=array('Product_Number','URL_Product','Price','System_of_Measurement');
        foreach ($data as $key => $value) {
            //$middle=Db::table('product_middle_table')->where('URL_Product','=',$value['URL_Product'])->find();

            //echo "insert into lily_products (`class_id`,`part_number`,`url_product`,`price`,`system`,`img`,`dimg`,`pdf`,`stp`,`other`) values (".$class_id.",'".$value['Product_Number']."','".$value['URL_Product']."','".$value['Price']."','".$value['System_of_Measurement']."','".$middle['img']."','".$middle['dimg']."','".$middle['pdf']."','".$middle['stp']."','".$middle['other']."');</br>";
            echo "insert into lily_products (`class_id`,`part_number`,`url_product`,`price`,`system`,`img`,`dimg`,`pdf`,`stp`,`other`) values (".$class_id.",'".$value['Product_Number']."','".$value['URL_Product']."','".$value['Price']."','".$value['System_of_Measurement']."','','','','','');</br>";
        }
    }

    public function checkno(){
        $data=Db::table('lily_products')->where([['id','>=',169284]])->select();
        foreach ($data as $key => $value) {
            $a=Db::query("select count(*) from lily_products where part_number='".$value['part_number']."'");
            if($a>1){
                echo "update lily_products set url_product=CONCAT(url_product,'_',id) where id>=169284 and url_product not like '%\_%'  and class_id in(212,1278,701,682) and part_number='".$value['part_number']."';</br>";
            }
        }
    }
}